<div class="_top">
    <div class="_top_left">
        <a class="icon-menu" event-click="{{'$Event.showTopMenu'}}"></a>
        <a class="icon-home" href="mobile.index.html#default/main"></a>
    </div>
    <div class="_top_right">
        {{#if !bus_loginer}}
        {{#if loginer}}
        <a class="{{$Cache.is_collect_current_bus&&'icon-star3'||'icon-star'}}" event-click="{{'$Event.user_collect_bus'}}"></a>
        <a class="icon-cart" href="mobile.index.html#default/cart"></a>
        <a href="mobile.personal.html" class="icon-user"></a>
        <!-- <a event-click="{{'$Event.loginer_show'}}" class="icon-user"></a> -->
        {{#else}}
        <a href="mobile.index.html#default/sign" class="icon-user2"></a>
        {{/if}}
        {{/if}}
    </div>

    <div class="_topmenu {{istopmenu&&'focus'}}" event-click="{{'$Event.showTopMenu'}}">
        <a href="#default/main"><div class="menuitem">首页</div></a>
        <a href="#default/goods_list"><div class="menuitem">商品列表</div></a>
        <a href="#default/tags"><div class="menuitem">商品分类</div></a>
        <a href="#default/storeinfo"><div class="menuitem">关于我们</div></a>
        <a href="#default/help"><div class="menuitem">省钱攻略</div></a>
    </div>
</div>
    
</div>
<div class="_topblock"></div>






<!-- 背景 -->
{{#if bus_info.config.is_use_bg_img}} {{#if bus_info.config.is_bg_img_alpha}}
<div class="themeimgblock" style="position: fixed;width: 100%;height:100%;top:0;left:0;background-color: rgba(255,255,255,0.6);z-index: -1;"></div>
{{/if}}
<img style="display:block;position: fixed;width: 100%;height: 100%;z-index: -2;top:0;left: 0;" bind-src="{{bus_info.config.using_bg_img}}{{#if bus_info.config.is_bg_img_blur}}?imageMogr2/blur/10x10{{/if}}">{{/if}}

<script type="text/vm">
    function(vm) {
        require(["common", "coAjax", "href", "eventManager", "appConfig"], function(jSouper, coAjax, href, eventManager) {
            function _check_collect_bus(collectBus) {
                var is_collect = true;
                if (jSouper.indexOf(collectBus, appConfig.bus_id) === -1) {
                    is_collect = false;
                }
                App.set("$Cache.is_collect_current_bus", is_collect)
            };
            eventManager.on("getLoginer", function() {
                //校验是否已经收藏过此商家
                var collectBus = App.get("loginer.collectBus") || [];
                _check_collect_bus(collectBus);
            });

            (window.coAjaxLoginUser = function(succ_cb) {
                // alert("获取登陆者信息……"+location.pathname)

                //获取登陆用户的信息
                /*
                 * 管理员相关的页面无需登录
                 */
                var no_user_login_pages = {
                    "/admin-beta.html": 1,
                    "/admin-login.html": 1
                }
                if (no_user_login_pages[location.pathname]) {
                    return;
                }
                // alert("开始获取"+appConfig.user.loginer)
                console.log("获取登陆者信息……", location.pathname);
                /*
                 * 获取登录者信息
                 */
                coAjax.get(appConfig.user.loginer, {
                    _: Math.random()
                }, function(data) {
                    // alert("success","用户登录成功");
                    console.log("登录者信息：", data.result);
                    userInfo = data.result;
                    App.set("loginer", userInfo);
                    //触发相关事件
                    eventManager.fire("getLoginer");
                    succ_cb && succ_cb();
                }, function(errorCode) {
                    // alert("用户未登录");
                    var muse_login_pages = {
                        "#default/sign": 1,
                        "#default/cart": 1
                    };
                    //未登录，不可进入个人页，强制跳转到登录页
                    if (muse_login_pages[location.pathname]) {
                        href.toLogin();
                    }
                });
            })();


            App.set("$Event.user_collect_bus", function() {
                if (App.get("$Cache.is_collect_current_bus")) {
                    coAjax["delete"](appConfig.user.collectBus_remove, {
                        bus_id: appConfig.bus_id
                    }, function(result) {
                        alert("已取消店铺收藏");
                        // App.set('$Cache.is_collect_current_bus',false);
                        _check_collect_bus(result.result);
                    }, function(errorCode, xhr, errorMsg) {
                        // alert("error",errorMsg)
                        _check_collect_bus(App.get("loginer.collectBus"));
                    });
                } else {
                    coAjax.post(appConfig.user.collectBus_add, {
                        bus_id: appConfig.bus_id
                    }, function(result) {
                        alert("success", "店铺收藏成功");
                        // App.set('$Cache.is_collect_current_bus',true);
                        _check_collect_bus(result.result);
                    }, function(errorCode, xhr, errorMsg) {
                        // alert("error",errorMsg)
                        _check_collect_bus(App.get("loginer.collectBus"));
                    });
                }
            });
            App.set("$Event.showTopMenu",function(){
                App.model.toggle("istopmenu");
                var count=0;
                var timer=setInterval(function(){
                    if (App.get("istopmenu")) {
                        if (count>3) {
                            App.model.toggle("istopmenu");
                            clearInterval(timer);
                        }else{
                            count+=1;
                        };
                    }else{
                        clearInterval(timer);
                    };
                },1000);
            })
        });
    }
</script>
